/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgStory
{
    public partial class TbCfgStoryShow
    {
        private readonly Dictionary<int, CfgStoryShow> _dataMap;
        private readonly List<CfgStoryShow> _dataList;

        /// <summary>
        /// id对应数据索引行数的映射表
        /// </summary>
        public IReadOnlyDictionary<int, int> Id2IndexMapping { get; private set; }
        /// <summary>
        /// 每个剧本的名字
        /// </summary>
        public string StoryName { get; private set; }

        public TbCfgStoryShow(ByteBuf _buf)
        {
            //first read common data
            _TbCommonStoryShow _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonStoryShow(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgStoryShow>(size * 3 / 2);
            _dataList = new List<CfgStoryShow>(size);

            for (int i = 0; i < size; i++)
            {
                CfgStoryShow _v;
                _v = CfgStoryShow.DeserializeCfgStoryShow(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<int, int> (__n0 * 3 / 2); Id2IndexMapping = __f0 ; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ) { int __k0; __k0 = _buf.ReadInt(); int __v0; __v0 = _buf.ReadInt(); __f0.Add(__k0, __v0); } }
            StoryName = _buf.ReadString();

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgStoryShow> DataMap => _dataMap;
        public IReadOnlyList<CfgStoryShow> DataList => _dataList;

        public CfgStoryShow Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgStoryShow] config not found,id:" + key.ToString());

            return null;
        }

        public CfgStoryShow GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "storyshow";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgStoryShow LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgStoryShow(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgStoryShow
    {
        private CfgStoryShow(ByteBuf _buf, _TbCommonStoryShow _commonData)
        {
            Id = _buf.ReadInt();
            Contents = _buf.ReadString();
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; JumpID = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            Speaker = _buf.ReadString();
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; NextDialogName = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; ChooseCondition = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; Service = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            BackgroundType = (StoryBackGroundType)(_buf.ReadInt());
            Background = _buf.ReadString();

            PostInit();
        }

        internal static CfgStoryShow DeserializeCfgStoryShow(ByteBuf _buf, _TbCommonStoryShow _commonData)
        {
            return new CfgStoryShow(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 对话文本
        /// </summary>
        public string Contents { get; private set; }
        /// <summary>
        /// 跳转Id
        /// </summary>
        public IReadOnlyList<int> JumpID { get; private set; }
        /// <summary>
        /// 说话人
        /// </summary>
        public string Speaker { get; private set; }
        /// <summary>
        /// 选项文本
        /// </summary>
        public IReadOnlyList<string> NextDialogName { get; private set; }
        /// <summary>
        /// 选项显示条件
        /// </summary>
        public IReadOnlyList<int> ChooseCondition { get; private set; }
        /// <summary>
        /// 服务
        /// </summary>
        public IReadOnlyList<IReadOnlyList<int>> Service { get; private set; }
        /// <summary>
        /// 背景图片类型
        /// </summary>
        public StoryBackGroundType BackgroundType { get; private set; }
        /// <summary>
        /// 背景图片路径
        /// </summary>
        public string Background { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonStoryShow
    {

        internal _TbCommonStoryShow(ByteBuf _buf)
        {
        }

    }
}
